<?php
if(!isset($_SESSION)) 
{ 
session_start(); 
} 
include '../connection/connection.php';	
$newlang = $_REQUEST['newlang'];
$iduser = $_REQUEST['iduser'];	
$emails = $_REQUEST['emails'];	
	
		if ($_REQUEST['newlang'] == "EN") {
			include "../value/value_en.php";
		} else if($_REQUEST['newlang'] == "VN") {
			include "../value/value_vn.php";
		}
		else {
			include "../value/value_kr.php";
		}
		
	if ( !isset($_REQUEST['page'] ))
	{
    	$page = 1 ;
	}else{
		$page = $_REQUEST['page'] ;
	}
	
	$rows_per_page = 20;
	$page_start = ( $page - 1 ) * $rows_per_page; 
	$page_end = $page * $rows_per_page;
	if(!isset($_REQUEST['page'])){
		$list["ui.email"]="DESC";
		$list["lv.viewer_ip"]="DESC";
		$list["lv.version"]="DESC";
		$list["lv.status"]="DESC";
		$list["lv.viewer_time"]="DESC";
		$list["lv.ins_time"]="DESC";
		
		$str="lv.ins_time";
		$_SESSION['sortn']=$str;
		$_SESSION['sort']=$list;
	}else{
		$str=$_SESSION['sortn'];
		$list=$_SESSION['sort'];
	}
	
	$datecurrent = date("Y-m-d");
	$temp = strtotime($datecurrent.'-1 days');
	$dateyesterday =  date("Y-m-d",$temp);
	
	$temp2 = strtotime($datecurrent.'-1 days');
	$dateLast_2 = date("Y-m-d",$temp2);
	
	$temp7 = strtotime($datecurrent.'-6 days');
	$dateLast_7 = date("Y-m-d",$temp7);
	
	$temp1months = strtotime($datecurrent.'-1 months');
	$date_1_month = date("Y-m-d",$temp1months);
	
		
		$sql = "SELECT lv.*,ui.email FROM `user_info` ui, log_viewer lv WHERE lv.id = ui.id AND ui.email='".$emails."' 
			AND lv.ins_time >'".$dateyesterday." 00:00:00' AND lv.ins_time<'".$dateyesterday." 23:59:59'  ";
		$selectlogviewer = mysql_query($sql." ORDER BY ".$str." ".$list[$str]);
		$number_of_page = ceil ( mysql_num_rows( $selectlogviewer ) / $rows_per_page ); 
		
		$_SESSION['sort']=$list;
?>

<div style="text-align: center;padding-left: 40px;">
<?=$l_from?> : <input type="text" id="searchfrom" name="searchfrom" style="height: 24px;width: 83px;"  onclick="getCalendar();">
<?=$l_to?> : <input type="text" id="searchto" name="searchto" style="height: 24px;width: 83px;"  onclick="getCalendar();">
<?=$namestatus?> : 
	<select id="status" name="status" style="height: 24px;width: 100px;padding-top: 3px;">
		<option value="all"><?=$l_all?></option>
		<option value="login"><?=$login?></option>
		<option value="logout"><?=$logout?></option>
	</select>
	
<input id="search" name="search" value="<?=$l_search?>"
			  class="buttonNormal" type="button" onclick="onclickButton_search_from_to(1,'<?=$search?>','<?=$emails?>')"/>
<input id="searchAll" name="searchAll" value="<?=$l_all?>"
			  class="buttonNormal" type="button" onclick="onclickButton_all(1,'<?=$search?>','<?=$emails?>')" />
			  
<input id="searchyesterday" name="searchyesterday" value="<?=$l_yesterday?>"
			  class="buttonNormalchoose" type="button" onclick="onclickButton_yesterday(1,'','<?=$dateyesterday?>','<?=$emails?>')"/>			  

<input id="searchone" name="searchone" value="<?php echo $oneday?>"
			  class="buttonNormal" type="button" onclick="onclickButton_1_day(1,'','<?=$datecurrent?>','<?=$emails?>')"/>

<input id="search2day" name="search2day" value="<?php echo $twoday?>"
			  class="buttonNormal" type="button" onclick="onclickButton_2_days(1,'','<?=$datecurrent?>','<?=$dateLast_2?>','<?=$emails?>')"/>

<input id="search1week" name="search1week" value="<?php echo $oneweek?>"
			  class="buttonNormal" type="button" onclick="onclickButton_7_days(1,'','<?=$datecurrent?>','<?=$dateLast_7?>','<?=$emails?>')"/>
<input id="search1month" name="search1month" value="<?php echo $one_month?>"
			  class="buttonNormal" type="button" onclick="onclickButton_1_month(1,'','<?=$datecurrent?>','<?=$date_1_month?>','<?=$emails?>')"/>
</div>
<div class="maind" style="padding-top: 15px;">
	<div id="logserver" style="padding-left: 40px;">
	<div><font style="color: red;font-size: 14px;font-weight: bold;">Detail user</font>
	
	</div>
	<div style="height: 10px;"></div>
		<table width="100%" cellpadding="0" cellspacing="0" class="mtable" id="tbLogViewer">
			<thead>
				<tr>
					<td align="center" style="width: 4%;color: #696969;"><?php echo $no?></td>
					<td align="center"><a onclick="sort_and_paging_lst_email_yesterday('<?=$page?>','ui.email',1,'<?=$search?>','','','<?=$dateyesterday?>','','','','','<?=$emails?>')" style="cursor: pointer;color: #027acc"><?php echo $useriforid ?></a></td>
					<td align="center"><a onclick="sort_and_paging_lst_email_yesterday('<?=$page?>','lv.viewer_ip',1,'<?=$search?>','','','<?=$dateyesterday?>','','','','','<?=$emails?>')" style="cursor: pointer;color: #027acc"><?php echo $remoteviewip ?></a></td>
					<td align="center"><a onclick="sort_and_paging_lst_email_yesterday('<?=$page?>','lv.version',1,'<?=$search?>','','','<?=$dateyesterday?>','','','','','<?=$emails?>')" style="cursor: pointer;color: #027acc"><?php echo $remoteviewerver?></a></td>
					<td align="center"><a onclick="sort_and_paging_lst_email_yesterday('<?=$page?>','lv.status',1,'<?=$search?>','','','<?=$dateyesterday?>','','','','','<?=$emails?>')" style="cursor: pointer;color: #027acc"><?php echo $status?></a></td>
					<td align="center"><a onclick="sort_and_paging_lst_email_yesterday('<?=$page?>','lv.viewer_time',1,'<?=$search?>','','','<?=$dateyesterday?>','','','','','<?=$emails?>')" style="cursor: pointer;color: #027acc"><?php echo $remoteviewtime?></a></td>
					<td align="center"><a onclick="sort_and_paging_lst_email_yesterday('<?=$page?>','lv.ins_time',1,'<?=$search?>','','','<?=$dateyesterday?>','','','','','<?=$emails?>')" style="cursor: pointer;color: #027acc"><?php echo $inserttime?></a></td>
				</tr>
			</thead>
			<?php
			if(mysql_num_rows($selectlogviewer)>0){
				$i=0;
				while ($row = mysql_fetch_array($selectlogviewer)){
					if ( $i >= $page_start ){?>
					<tr>
						<td align="center" style="width:4%;background: white;color: #5D5D5D;font-weight: normal;"><?php echo $i+1?></td>
						<td align="center" style="background: white;color: #5D5D5D;font-weight: normal;"><?php echo $row[email] ?></td>
						<td align="center" style="background: white;color: #5D5D5D;font-weight: normal;"><?php echo $row[viewer_ip] ?></td>
						<td align="center" style="background: white;color: #5D5D5D;font-weight: normal;"><?php echo $row[version]?></td>
						<td align="center" style="background: white;color: #5D5D5D;font-weight: normal;"><?php echo $row[status]?></td>
						<td align="center" style="background: white;color: #5D5D5D;font-weight: normal;"><?php echo $row[viewer_time]?></td>
						<td align="center" style="background: white;color: #5D5D5D;font-weight: normal;"><?php echo $row[ins_time]?></td>
					</tr>
			<?php
					}
						$i++;
						if ($i >= $page_end){
							break;
						}
					}
				}
			?>
			
			<tr>
					<td colspan="8" class="rf-dt-shdr-c">
						<span style="padding:1px; display: inline-block;">
													
							<?php if ( $number_of_page > 1 ) 
							{ 
								if ($page==1)
									$p=2;
								else if ($page==$number_of_page)
									$p=$number_of_page-1;
								else $p=$page;
								if($page!=1){?>
									<a onclick="sort_and_paging_lst_email_yesterday(<?=1?>,'<?=$str?>',0,'<?=$search?>','','','<?=$dateyesterday?>','','','','','<?=$emails?>')" ><span class='button_next'><?php echo "<<<";?></span> </a>
									<a onclick="sort_and_paging_lst_email_yesterday(<?=($page-1)?>,'<?=$str?>',0,'<?=$search?>','','','<?=$dateyesterday?>','','','','','<?=$emails?>')"><span class='button_next'><?php echo "<<";?></span> </a>
								<?php  }
								else{
									echo "<span class='button_next'><<<</span> "; 
									echo "<span class='button_next'><<</span> ";
								}
								for ( $i = $p-1; $i <= $p+1; $i++ ) {	
										if ($i<=$number_of_page && $i>0)
										
											if ($i==$page){
												echo "<span class='button_next'><b>".$i."</b></span>"; 
											}else{
											?>
												<a onclick="sort_and_paging_lst_email_yesterday(<?=$i?>,'<?=$str?>',0,'<?=$search?>','','','<?=$dateyesterday?>','','','','','<?=$emails?>')"><span class="button_next">
												<?php 
												echo $i;
												?>
												</span> </a>
												<?php 
											}
										?>
									
								<?php 
										}
									
									if($page!=$number_of_page){ ?>
										<a onclick="sort_and_paging_lst_email_yesterday(<?=($page+1)?>,'<?=$str?>',0,'<?=$search?>','','','<?=$dateyesterday?>','','','','','<?=$emails?>')"><span class='button_next'><?php echo ">>";?></span> </a>
										<a onclick="sort_and_paging_lst_email_yesterday(<?=$number_of_page?>,'<?=$str?>',0,'<?=$search?>','','','<?=$dateyesterday?>','','','','','<?=$emails?>')"><span class='button_next'><?php echo ">>>";?></span> </a>
									<?php }
									else{
										echo "<span class='button_next'>>></span> ";
										echo "<span class='button_next'>>>></span> ";
									}
								}
							
								
								?>
																					
						</span>
					</td>
				</tr>

		</table>
	</div>
</div>